home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / convrtrs / pbmplus / update4.lha / src / extra / ppmtomitsu.c.diff < prev    next >
Encoding:
Text File  |  1993-07-08  |  11.1 KB  |  337 lines

  1. *** ppmtomitsu.c.orig    Wed Mar 31 12:24:24 1993
  2. --- ppmtomitsu.c    Thu Jul 08 19:48:53 1993
  3. ***************
  4. *** 3,8 ****
  5. --- 3,13 ----
  6.   **                (or the S3410-30 parallel interface)
  7.   **
  8.   ** Copyright (C) 1992,93 by S.Petra Zeidler
  9. + ** Minor modifications by Ingo Wilken:
  10. + **  - moved large arrays off the stack into globals (A_SMALLSTACK)
  11. + **  - mymalloc() and check_and_rotate() functions for often used
  12. + **    code fragments.  Reduces code size by a few KB.
  13. + **  - use pm_error() instead of fprints(stderr)
  14.   **
  15.   ** This software was written for the Max Planck Institut fuer Radioastronomie,
  16.   ** Bonn, Germany, Optical Interferometry group
  17. ***************
  18. *** 19,27 ****
  19. --- 24,41 ----
  20.   #include "ppm.h"
  21.   #include "ppmcmap.h"
  22.   #include "pbmplus.h"
  23. + #ifdef __STDC__
  24. + #include <stdlib.h>
  25. + #else
  26.   #include <memory.h>
  27. + #endif
  28.   #include "mitsu.h"
  29.   
  30. + #ifdef A_SMALLSTACK
  31. + hashinfo colorhashtable[HASHSIZE];
  32. + #endif
  33.   #ifdef __STDC__
  34.   void main(int argc, char *argv[] )
  35.   #else
  36. ***************
  37. *** 31,37 ****
  38. --- 45,53 ----
  39.   #endif
  40.       {
  41.       FILE             *ifp;
  42. + #ifndef A_SMALLSTACK
  43.       hashinfo         colorhashtable[HASHSIZE];
  44. + #endif
  45.       struct hashinfo  *hashrun;
  46.       pixel            *xP;
  47.       int              argn;
  48. ***************
  49. *** 70,76 ****
  50.           }
  51.       else if (pm_keymatch(argv[argn], "-media", 2)) {
  52.           ++argn;
  53. !         if (argn == argc || sscanf(argv[argn], "%s", media) < 1)
  54.               pm_usage(usage);
  55.           else if (mytoupper(media[0]) != 'A')
  56.               pm_usage(usage);
  57. --- 86,92 ----
  58.           }
  59.       else if (pm_keymatch(argv[argn], "-media", 2)) {
  60.           ++argn;
  61. !         if (argn == argc || sscanf(argv[argn], "%15s", media) < 1)
  62.               pm_usage(usage);
  63.           else if (mytoupper(media[0]) != 'A')
  64.               pm_usage(usage);
  65. ***************
  66. *** 130,147 ****
  67.   
  68.           ppm_readppminit(ifp, &cols, &rows, &maxval, &format);
  69.           pixelrow = (pixel *) ppm_allocrow(cols);
  70. !         if ((redrow = malloc(cols * sizeof(char))) == NULL) {
  71. !             fprintf(stderr, "ppmtomitsu: malloc failed, exiting\n");
  72. !             exit(1);
  73. !         }
  74. !         if ((greenrow = malloc( cols * sizeof(char))) == NULL) {
  75. !             fprintf(stderr, "ppmtomitsu: malloc failed, exiting\n");
  76. !             exit(1);
  77. !         }
  78. !         if ((bluerow = malloc( cols * sizeof(char))) == NULL) {
  79. !             fprintf(stderr, "ppmtomitsu: malloc failed, exiting\n");
  80. !             exit(1);
  81. !         }
  82.           lineputinit(cols, rows, sharpness, enlarge, copy, medias);
  83.   
  84.           for ( row = 0; row < rows; ++row ) {
  85. --- 146,154 ----
  86.   
  87.           ppm_readppminit(ifp, &cols, &rows, &maxval, &format);
  88.           pixelrow = (pixel *) ppm_allocrow(cols);
  89. !         redrow = mymalloc(cols * sizeof(char));
  90. !         greenrow = mymalloc(cols * sizeof(char));
  91. !         bluerow = mymalloc(cols * sizeof(char));
  92.           lineputinit(cols, rows, sharpness, enlarge, copy, medias);
  93.   
  94.           for ( row = 0; row < rows; ++row ) {
  95. ***************
  96. *** 215,227 ****
  97.                       else {
  98.                           while (hashrun->next != NULL)
  99.                               hashrun = hashrun->next;
  100. !                         if ((hashrun->next = 
  101. !                         (struct hashinfo *) malloc(sizeof(struct hashinfo)))
  102. !                                                                 == NULL) {
  103. !                             fprintf(stderr, "%s: malloc failed, exiting\n",
  104. !                                 argv[0]);
  105. !                             exit(2);
  106. !                         }
  107.                           hashrun = hashrun->next;
  108.                           hashrun->color = (table[colval]).color;
  109.                           hashrun->flag  = colval;
  110. --- 222,229 ----
  111.                       else {
  112.                           while (hashrun->next != NULL)
  113.                               hashrun = hashrun->next;
  114. !                         hashrun->next =
  115. !                             (struct hashinfo *) mymalloc(sizeof(struct hashinfo));
  116.                           hashrun = hashrun->next;
  117.                           hashrun->color = (table[colval]).color;
  118.                           hashrun->flag  = colval;
  119. ***************
  120. *** 246,258 ****
  121.                       else {
  122.                           while (hashrun->next != NULL)
  123.                               hashrun = hashrun->next;
  124. !                         if ((hashrun->next = 
  125. !                         (struct hashinfo *) malloc(sizeof(struct hashinfo)))
  126. !                                                                 == NULL) {
  127. !                             fprintf(stderr, "%s: malloc failed, exiting\n",
  128. !                                 argv[0]);
  129. !                             exit(2);
  130. !                         }
  131.                           hashrun = hashrun->next;
  132.                           hashrun->color = (table[colval]).color;
  133.                           hashrun->flag  = colval;
  134. --- 248,255 ----
  135.                       else {
  136.                           while (hashrun->next != NULL)
  137.                               hashrun = hashrun->next;
  138. !                         hashrun->next =
  139. !                             (struct hashinfo *) mymalloc(sizeof(struct hashinfo));
  140.                           hashrun = hashrun->next;
  141.                           hashrun->color = (table[colval]).color;
  142.                           hashrun->flag  = colval;
  143. ***************
  144. *** 269,277 ****
  145.                           if (hashrun->next != NULL)
  146.                               hashrun = hashrun->next;
  147.                           else {
  148. !                             fprintf(stderr, "%s: you just found a letal bug.\n",
  149. !                                 argv[0]);
  150. !                             exit(1);
  151.                           }
  152.                       datum(hashrun->flag);
  153.                   }
  154. --- 266,272 ----
  155.                           if (hashrun->next != NULL)
  156.                               hashrun = hashrun->next;
  157.                           else {
  158. !                             pm_error("you just found a lethal bug.");
  159.                           }
  160.                       datum(hashrun->flag);
  161.                   }
  162. ***************
  163. *** 395,425 ****
  164.       default:
  165.           SHARPNESS(SP_USER);
  166.       }
  167. !     if (cols > rows) {
  168. !         ROTATEIMG(DOROTATE);                        /* rotate image */
  169. !         if (enlarge*rows > medias.maxcols || enlarge*cols > medias.maxrows) {
  170. !             fprintf(stderr, "ppmtomitsu: Image too large, MaxPixels = %d x %d\n"
  171. !                           , medias.maxrows, medias.maxcols);
  172. !             exit(1);
  173. !         }
  174. !         HPIXELS(cols);
  175. !         VPIXELS(rows);
  176. !         HPIXELSOFF((medias.maxcols/enlarge - rows)/2);
  177. !         VPIXELSOFF((medias.maxrows/enlarge - cols)/2);
  178. !         pm_message("rotating image for output");
  179. !     }
  180. !     else {
  181. !         ROTATEIMG(DONTROTATE);
  182. !         if (enlarge*rows > medias.maxrows || enlarge*cols > medias.maxcols) {
  183. !             fprintf(stderr, "ppmtomitsu: Image too large, MaxPixels = %d x %d\n"
  184. !                           , medias.maxrows, medias.maxcols);
  185. !             exit(1);
  186. !         }
  187. !         HPIXELS(cols);
  188. !         VPIXELS(rows);
  189. !         HPIXELSOFF((medias.maxcols/enlarge - cols)/2);
  190. !         VPIXELSOFF((medias.maxrows/enlarge - rows)/2);
  191. !     }
  192.       DATASTART;
  193.       return;
  194.   }
  195. --- 390,396 ----
  196.       default:
  197.           SHARPNESS(SP_USER);
  198.       }
  199. !     check_and_rotate(cols, rows, enlarge, medias);
  200.       DATASTART;
  201.       return;
  202.   }
  203. ***************
  204. *** 495,525 ****
  205.   #endif /*__STDC__*/
  206.   {
  207.       DONELOOKUPTABLE;
  208. !     if (cols > rows) {
  209. !         ROTATEIMG(DOROTATE);                        /* rotate image */
  210. !         if (enlarge*rows > medias.maxcols || enlarge*cols > medias.maxrows) {
  211. !             fprintf(stderr, "ppmtomitsu: Image too large, MaxPixels = %d x %d\n"
  212. !                           , medias.maxrows, medias.maxcols);
  213. !             exit(1);
  214. !         }
  215. !         HPIXELS(cols);
  216. !         VPIXELS(rows);
  217. !         HPIXELSOFF((medias.maxcols/enlarge - rows)/2);
  218. !         VPIXELSOFF((medias.maxrows/enlarge - cols)/2);
  219. !         pm_message("rotating image for output");
  220. !     }
  221. !     else {
  222. !         ROTATEIMG(DONTROTATE);
  223. !         if (enlarge*rows > medias.maxrows || enlarge*cols > medias.maxcols) {
  224. !             fprintf(stderr, "ppmtomitsu: Image too large, MaxPixels = %d x %d\n"
  225. !                           , medias.maxrows, medias.maxcols);
  226. !             exit(1);
  227. !         }
  228. !         HPIXELS(cols);
  229. !         VPIXELS(rows);
  230. !         HPIXELSOFF((medias.maxcols/enlarge - cols)/2);
  231. !         VPIXELSOFF((medias.maxrows/enlarge - rows)/2);
  232. !     }
  233.       DATASTART;
  234.       return;
  235.   }
  236. --- 466,472 ----
  237.   #endif /*__STDC__*/
  238.   {
  239.       DONELOOKUPTABLE;
  240. !     check_and_rotate(cols, rows, enlarge, medias);
  241.       DATASTART;
  242.       return;
  243.   }
  244. ***************
  245. *** 583,594 ****
  246.       default:
  247.           SHARPNESS(SP_USER);
  248.       }
  249.       if (cols > rows) {
  250.           ROTATEIMG(DOROTATE);                        /* rotate image */
  251.           if (enlarge*rows > medias.maxcols || enlarge*cols > medias.maxrows) {
  252. !             fprintf(stderr, "ppmtomitsu: Image too large, MaxPixels = %d x %d\n"
  253. !                           , medias.maxrows, medias.maxcols);
  254. !             exit(1);
  255.           }
  256.           HPIXELS(cols);
  257.           VPIXELS(rows);
  258. --- 530,573 ----
  259.       default:
  260.           SHARPNESS(SP_USER);
  261.       }
  262. +     check_and_rotate(cols, rows, enlarge, medias);
  263. +     return;
  264. + }
  265. + #ifdef __STDC__
  266. + static void *
  267. + mymalloc(long bytes)
  268. + #else
  269. + static char *
  270. + mymalloc(bytes)
  271. +     long bytes;
  272. + #endif
  273. + {
  274. +     void *mem;
  275. +     mem = malloc(bytes);
  276. +     if( mem == NULL )
  277. +         pm_error("out of memory allocating %d bytes", bytes);
  278. +     return mem;
  279. + }
  280. + #ifdef __STDC__
  281. + static void
  282. + check_and_rotate(int cols, int rows, int enlarge, struct mediasize medias)
  283. + #else
  284. + static void
  285. + check_and_rotate(cols, rows, enlarge, medias)
  286. +     int cols, rows, enlarge;
  287. +     struct mediasize medias;
  288. + #endif
  289. + {
  290.       if (cols > rows) {
  291.           ROTATEIMG(DOROTATE);                        /* rotate image */
  292.           if (enlarge*rows > medias.maxcols || enlarge*cols > medias.maxrows) {
  293. !             pm_error("Image too large, MaxPixels = %d x %d", medias.maxrows, medias.maxcols);
  294.           }
  295.           HPIXELS(cols);
  296.           VPIXELS(rows);
  297. ***************
  298. *** 599,607 ****
  299.       else {
  300.           ROTATEIMG(DONTROTATE);
  301.           if (enlarge*rows > medias.maxrows || enlarge*cols > medias.maxcols) {
  302. !             fprintf(stderr, "ppmtomitsu: Image too large, MaxPixels = %d x %d\n"
  303. !                           , medias.maxrows, medias.maxcols);
  304. !             exit(1);
  305.           }
  306.           HPIXELS(cols);
  307.           VPIXELS(rows);
  308. --- 578,584 ----
  309.       else {
  310.           ROTATEIMG(DONTROTATE);
  311.           if (enlarge*rows > medias.maxrows || enlarge*cols > medias.maxcols) {
  312. !             pm_error("Image too large, MaxPixels = %d x %d", medias.maxrows, medias.maxcols);
  313.           }
  314.           HPIXELS(cols);
  315.           VPIXELS(rows);
  316. ***************
  317. *** 608,612 ****
  318.           HPIXELSOFF((medias.maxcols/enlarge - cols)/2);
  319.           VPIXELSOFF((medias.maxrows/enlarge - rows)/2);
  320.       }
  321. -     return;
  322.   }
  323. --- 585,589 ----
  324.           HPIXELSOFF((medias.maxcols/enlarge - cols)/2);
  325.           VPIXELSOFF((medias.maxrows/enlarge - rows)/2);
  326.       }
  327.   }
  328.